<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri ="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<div class="page-header">
	<h3>访问路径列表</h3>
</div>
<table class="table table-striped table-hover .table-condensed">
	<thead>
		<tr>
			<th>url</th>
			<th>限制次数</th>
			<th>描述</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="data"></tbody>
</table>
<div id="layPage" class="text-center"></div>

<div id="editPanel" class="panel panel-default"
	style="display: none; margin-bottom: 0; width: 300px;heigh:700">
	<div class="panel-heading">
		<h3 class="panel-title">修改名称</h3>
	</div>
	<div class="panel-body">
	<%-- action="${basePath}/accessManager/edit" --%>
		<form role="form" id="form">
			<div class="form-group">
				<input name="id" type="text" hidden="hidden" />
				 <label for="name">url</label>
				 <input name="url" type="text" class="form-control" id="url" /><br /> 
				 <label for="name">访问限制数</label>
				 <input name="limitTimes" type="number" class="form-control" id="limitTimes" /><br /> 
				 <label for="description">产品描述</label>
				<textarea name="urlDesc" class="form-control" rows="4" style="resize: none;"></textarea>
				<br /> 
			</div>
			<br /> <input id = "submit" name="submit" type="submit" value="确认"
				class="btn btn-default pull-right" />
		</form>
	</div>
</div>

<script type="text/javascript">
	var pageNum = 1;
	var basePath = $("#basePath").val();
	
	$(function(){
		goPage(1);
	})
	
	function goPage(pageNum){
		$.post(basePath+"/accessManager/doList",{pageNum:pageNum} ,function(qr){
			var html = '';
			if(!qr||qr.success==false){
				html += '获取数据失败'	;
			
			}else{
				var data = qr.page.list;
				for(var i = 0; i<data.length;i++){
					html+='<tr>'
					+'<td>'+(data[i].url||"")+'</td>'
					+'<td>'+(data[i].limitTimes||"")+'</td>'
					+'<td>'+(data[i].urlDesc||"")+'</td>'
					+'<td><a uid="'+data[i].id+'" class="btn btn-default del">删除</a>'
					+'<a uid="'+data[i].id+'" url="'+data[i].url+'" urlDesc="'+data[i].urlDesc+'" limitTimes="'+data[i].limitTimes+'" class="btn btn-default edit ">修改</a></td>'
					+'</tr>';
				}
			}
			$("#data").empty();
			paging(qr.page);
			$("#data").append(html);
			$(".edit").click(function(){
				var id = $(this).attr("uid");
				$("input[name=id]").val(id);
				$("textarea[name=urlDesc]").val($(this).attr("urlDesc"));
				$("input[name=url]").val($(this).attr("url"));
				$("input[name=limitTimes]").val($(this).attr("limitTimes"));
				$("#editPanel").trigger("chosen:updated");
				window.editLayer = layer.open({
					type : 1,
					title : false,
					closeBtn : 1,
					shadeClose : true,
					content : $('#editPanel')
				});
			});
			$("#submit").click(function(){
				var params = $("#form").serializeArray();
				$.post(basePath+"/accessManager/edit",params,function(qr){
					if (qr.result.success) {
						layer.msg(qr.result.message, {icon : 1,time : 1000}, function() {
							goPage(1);
						});
					} else {
						layer.msg(qr.result.message, {icon : 2});
					}	
				});
				
			});
			$(".del").click(function() {
				var deleteId = $(this).attr("uid");
				layer.confirm('确定要删除', {
					icon : 3,
					title : '提示'
				}, function(index) {
					$.post(basePath+"/accessManager/delete", {id : deleteId}, function(result) {
						if (result.result.success) {
							layer.msg(result.result.message, {icon : 1,time : 1000}, function() {
								goPage(1);
							});
						} else {
							layer.msg(result.result.message, {icon : 2});
						}
					});
					layer.close(index);
				});
			});
		});
	}
	
 	function paging(page){
		laypage({
		    cont: 'layPage',
		    pages: page.pageCount,
		    curr: page.pageNum,
		    jump: function(obj,first){
		    	if(!first){
		    		goPage(obj.curr);
		    	}
		    }
		});
	} 

</script>


